package entrance;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import action.DataProcessAction;

/**
 * Hello world!
 * 
 */
public class TcpServer {

	public void start() throws IOException {
		// open port
		ServerSocket server = new ServerSocket(9988);// 选取1024以上且不占用的
		Socket socket = server.accept();// 开发端口 且塞当前线程
		// 具有输入输出流 相当yu插座 或网卡插口
		// 可以不用管了 下面开始IO的表演
		OutputStream out = socket.getOutputStream();
		InputStream in = socket.getInputStream();
		out.write("plz input command!\r\n".getBytes());
		while (true) {
			if (new DataProcessAction().action(in, out) == false) {
				out.write("bye bye!!\r\n".getBytes());
				break;
			}
			out.write("plz input command!\r\n".getBytes());
		}
		out.close();
		in.close();
		socket.close();
		server.close();

	}

	public static void main(String[] args) throws IOException {

		new TcpServer().start();
	}

}
